package com.fulu.javabase.singleton.test;

import com.fulu.javabase.singleton.Singleton6;

import java.util.concurrent.*;

/**
 * 测试线程不安全的单例
 */
public class SingletonTest6 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 多线程情况

        //SingletonTest6.class.getClassLoader().loadClass()

        Callable<Singleton6> callable = new Callable<Singleton6>() {
            public Singleton6 call() throws Exception {
                return Singleton6.getInstance();
            }
        };

        ExecutorService es = Executors.newFixedThreadPool(2);
        Future<Singleton6> f1 = es.submit(callable);
        Future<Singleton6> f2 = es.submit(callable);

        Singleton6 s1 = f1.get();
        Singleton6 s2 = f2.get();

        System.out.println(s1 == s2);

        es.shutdown();

    }
}
